﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region Linkman

        public List<tb_Linkman> GetAllLinkman()
        {

            var query = (from obj in this.tb_Linkmans
                         where obj.IsDelete==0
                         select obj).ToList();
            return query;
        }

        public tb_Linkman GetLinkmanById(int id)
        {
            return this.tb_Linkmans.SingleOrDefault(tb_Linkmans => tb_Linkmans.Id == id);
        }

        public void CreateLinkman(tb_Linkman entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_Linkmans.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyLinkman(tb_Linkman entity)
        {
            tb_Linkman instance = this.tb_Linkmans.SingleOrDefault(p => p.Id == entity.Id);
            instance.Remark = entity.Remark;
            instance.Tel = entity.Tel;
            instance.Title = entity.Title;
            instance.Mobile = entity.Mobile;
            instance.Email = entity.Email;
            instance.Name = entity.Name; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;
            instance.Name = entity.Name;
         
            this.SubmitChanges();
        }
        public void DeleteLinkman(tb_Linkman entity)
        {
            tb_Linkman deleteEntity = tb_Linkmans.SingleOrDefault(p => p.Id == entity.Id);
            tb_Linkmans.DeleteOnSubmit(deleteEntity);
            this.SubmitChanges();
        }

        #endregion 

    }
}
